/* main.c file */
#include <gtk/gtk.h>
#include "ouritem.h"

static GtkWidget *entry = NULL;

//以下函数为自定义控件ouritem的"ouritem_ok"信号的回调函数
void on_item_ok(GtkWidget *widget, gpointer data)
{
    gtk_entry_set_text(GTK_ENTRY(entry),"OK!项目一录入结束");
}

int main(int argc, char* argv[])
{
    GtkWidget *window, *vbox, *item1, *button;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window),"自定义控件测试");
    g_signal_connect(G_OBJECT(window),"delete_event",
                        G_CALLBACK(gtk_main_quit),NULL);
    gtk_container_set_border_width(GTK_CONTAINER(window),10);

    vbox = gtk_vbox_new(FALSE,0);
    gtk_container_add(GTK_CONTAINER(window),vbox);

    //创建自定义控件
    item1 = our_item_new_with_label("项目一：");
    //为自定义控件的"ouritem_ok"信号连接函数
    g_signal_connect(G_OBJECT(item1),"ouritem_ok",
                        G_CALLBACK(on_item_ok),NULL);

    gtk_box_pack_start(GTK_BOX(vbox),item1,FALSE,FALSE,5);

    entry = gtk_entry_new();
    gtk_box_pack_start(GTK_BOX(vbox),entry,FALSE,FALSE,5);
    button = gtk_button_new_with_label("退出");
    gtk_box_pack_start(GTK_BOX(vbox),button,FALSE,FALSE,5);
    g_signal_connect(G_OBJECT(button),"clicked",
                        G_CALLBACK(gtk_main_quit),NULL);
    gtk_widget_show_all(window);

    gtk_main();

    return FALSE;

}
